package service.Impl;

import dao.users.SysAccountsDao;
import entity.SysAccounts;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.SysAccountsService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 账号(SysAccounts)表服务实现类
 *
 * @author liujh
 * @since 2020-08-10 16:57:30
 */
@Service("sysAccountsService")
@Slf4j
public class SysAccountsServiceImpl implements SysAccountsService {


    @Autowired
    private SysAccountsDao sysAccountsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SysAccounts queryById(Long id) {
        return this.sysAccountsDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<SysAccounts> queryAllByLimit(int offset, int limit) {
        return this.sysAccountsDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param sysAccounts 实例对象
     * @return 实例对象
     */
    @Override
    public SysAccounts insert(SysAccounts sysAccounts) {
        this.sysAccountsDao.insert(sysAccounts);
        return sysAccounts;
    }

    /**
     * 修改数据
     *
     * @param sysAccounts 实例对象
     * @return 实例对象
     */
    @Override
    public SysAccounts update(SysAccounts sysAccounts) {
        this.sysAccountsDao.update(sysAccounts);
        return this.queryById(sysAccounts.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.sysAccountsDao.deleteById(id) > 0;
    }

    @Override
    public SysAccounts queryByAccount(String username) {
        return this.sysAccountsDao.queryByAccount(username);
    }
}